package com.kvest.sherlocktest;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.app.ActionBar;
/**
 * Created with IntelliJ IDEA.
 * User: r.belokon
 * Date: 15.04.13
 * Time: 12:59
 * To change this template use File | Settings | File Templates.
 */
public class ListmodeSherlockActivity extends SherlockActivity implements ActionBar.OnNavigationListener {
    private static final String[] data = new String[] { "one", "two", "three" };
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView tv = new TextView(this);
        tv.setText("This is ListmodeSherlockActivity");
        setContentView(tv);

        setActionBar();
    }

    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            Toast.makeText(this, "This is HOME", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, item.getTitle(), Toast.LENGTH_SHORT).show();
        }

        return super.onMenuItemSelected(featureId, item);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void setActionBar() {
        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, data);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        getSupportActionBar().setListNavigationCallbacks(adapter, this);
    }

    @Override
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        Toast.makeText(this, "selected: position = " + itemPosition + ", id = "
                + itemId + ", " + data[itemPosition], Toast.LENGTH_SHORT).show();
        return false;
    }
}